import { SessionStorage, LocalStorage } from './storage'

const TokenKey = 'Token'
const NoLoginTokenKey = 'NoLoginToken'
const RefreshToken = 'RefreshToken'
const SNO = 'sno'
const DeviceRandomId = 'DeviceRandomId'

// RefreshToken 过期时间 单位毫秒
const REFRESH_TOKEN_EXPIRES = 8 * 3600 * 1000

export function getToken() {
  return SessionStorage.get(TokenKey)
}

export function setToken(token) {
  SessionStorage.set(TokenKey, token)
}

export function setNoLoginToken(token) {
  SessionStorage.set(NoLoginTokenKey, token)
}

export function getNoLoginToken(token) {
  return SessionStorage.get(NoLoginTokenKey)
}

export function setSno(sno) {
  SessionStorage.set(SNO, sno)
}

export function getSno() {
  return SessionStorage.get(SNO)
}

export function getRefreshToken() {
  return SessionStorage.getByTime(RefreshToken, REFRESH_TOKEN_EXPIRES)
}

export function setRefreshToken(token) {
  SessionStorage.setByTime(RefreshToken, token)
}

// id为专辑id,index为该专辑下播放的第几个视频
export function setPlayingVideo(id, index) {
  SessionStorage.set(id, index)
}

export function getPlayingVideo(id) {
  return SessionStorage.get(id)
}

export function setDeviceRandomId(deviceRandomId) {
  LocalStorage.set(DeviceRandomId, deviceRandomId)
}

export function getDeviceRandomId() {
  return LocalStorage.get(DeviceRandomId)
}

export function removeToken() {
  SessionStorage.remove(TokenKey)
}

export function removeSno() {
  SessionStorage.remove(SNO)
}

export function removeRefreshToken() {
  SessionStorage.remove(RefreshToken)
}

export function removeAllToken() {
  removeToken()
  removeRefreshToken()
}
